/**
 * @project readnote
 * @Title ExpostulationServiceImpl.java
 * @author huxh
 * @date 2012-2-12
 **/
package com.readnote.expostulation.service.impl;

import java.util.Collection;
import java.util.Date;

import com.cr.backbone.hibenate.AppBaseServiceImpl;
import com.readnote.expostulation.dao.ExpostulationDAO;
import com.readnote.expostulation.model.Expostulation;
import com.readnote.expostulation.service.ExpostulationService;
import com.readnote.user.model.User;

public class ExpostulationServiceImpl extends AppBaseServiceImpl<Expostulation> implements ExpostulationService {

	public ExpostulationDAO getDAO() {
		return ((ExpostulationDAO)(dao));
	}
	
	/**
	 * 保存励志谏言
	 * 插入、更新励志谏言记录
	 * @methodDescribe
	 * @param expostulation
	 * @param user
	 * @param applyDate
	 * @return
	 * @author xianghua.hu
	 * @date 2012-3-6 下午04:49:23
	 */
	public Long saveExpostulation(Expostulation expostulation, User user,
			Date applyDate){
		Long id=null;
		if(expostulation.isNullRow()){
			expostulation.setCreateUser(user);
			expostulation.setCreateDate(applyDate);
			id = getDAO().save(expostulation);
		}else{
			Expostulation _expostulation=getDAO().get(expostulation.getId());
			_expostulation.setContent(expostulation.getContent());
			_expostulation.setCreateUser(user);
			_expostulation.setCreateDate(applyDate);
			getDAO().update(_expostulation);
			id = expostulation.getId();
		}
		return id;
	}
	
	
	/**
	 * 获取最新发布的谏言，by 用户
	 * @methodDescribe
	 * @param user
	 * @return
	 * @author xianghua.hu
	 * @date 2012-3-6 下午05:16:25
	 */
	public Expostulation getExpostulationTopOneByCreateDateDesc(User user){
		Expostulation expostulation = getDAO().getExpostulationTopOneByCreateDateDesc(user);
		return expostulation ;
	}
	
	/**
	 * 根据用户获取检验，根据创建时间倒序
	 * @methodDescribe
	 * @author xianghua.hu
	 * @date 2012-5-16 
	 */
	public Collection<Expostulation> getListExpostulationByUserOrderCreateDateDesc(User user){
		Collection<Expostulation> expostulations=getDAO().getListExpostulationByUserOrderCreateDateDesc(user);;
		return expostulations ;
		
	}
	
	
}
